/**
 * @(#)ContactController.java, 2010-5-20. 
 * 
 * Copyright 2010 Youdao, Inc. All rights reserved.
 * YOUDAO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.rsstuan.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.rsstuan.mail.MailSender;
import com.rsstuan.utils.CityUtils;

/**
 *
 * @author guosq
 *
 */
public class ContactController extends SpringController {
    
    private MailSender sender;
    
    private String RESULT_VM = "main/result";
    
    private String CONTACT_VM = "main/contact";
   
    public ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) {
        
    	
    	if (request.getParameter("submit") != null) {
            String idStr = request.getParameter("cityid");
            if (idStr != null) {
                String city = CityUtils.getCityString(idStr);
            }
            String title = request.getParameter("title");
            String content = request.getParameter("content");
            String email = request.getParameter("email");
            sender.sendFeedBack(email, title, content);
        
            Map<String, Object> model = new HashMap<String,Object>();
            model.put("title", "发送成功");
            model.put("content", "发送成功, 您的意见对我们非常重要，我们将尽快处理"); 
            return createModelAndView(request, response, RESULT_VM, model);
        } 
    	else {
			Map<String, Object> model = new HashMap<String, Object>();

			String city = null;
			int cityid = 1;
			if (request.getParameter("cityid") != null) {
				try {
					cityid = Integer.parseInt(request.getParameter("cityid"));
					city = CityUtils.getCity(cityid);
				} catch (Exception e) {
				}
			}
			if (city == null)
				city = CityUtils.DEFAULT_CITY;
			model.put("city", city);
			model.put("cityid", cityid);
			return createModelAndView(request, response, CONTACT_VM, model);
		}
       
    }

    public void setSender(MailSender sender) {
        this.sender = sender;
    }
    
    

}
